import type ZipaperType from "zipaper/types/Zipaper"

// 获取DOM结构意义上的父节点
export function getParentInstance(name: string, callback: (instance: ZipaperType) => void) {

    let getItemById = (id: string) => {
        for (let item of this.__parent.__children) {
            if (item.__uniqueId === id && item.name === name) {
                return item
            }
        }
    }

    let el = this.__el

    setTimeout(() => {
        while (el.parentNode) {
            el = el.parentNode
            if (el.__uniqueId__) {
                let item = getItemById(el.__uniqueId__)
                if (item) {
                    callback(item)
                    break
                }
            }
        }
    })

}